﻿using AccumulateApp.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace AccumulateApp.Behavior
{
    public class WindowHeaderBehavior : Behavior<Border>
    {
        private Window _window;

        protected override void OnAttached()
        {
            base.OnAttached();

            _window = CommonHelper.FindVisualParent<Window>(AssociatedObject);

            //AssociatedObject为关联对象， 是Behavior<T>中的T
            AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown;
        }

        private void AssociatedObject_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _window.DragMove();
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.MouseLeftButtonDown -= AssociatedObject_MouseLeftButtonDown;
        }
    }
}
